package cn.spcloud.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

@RestController
public class OrderController {

	@Autowired
	RestTemplate restTemplate;

	@RequestMapping("/info")
	public String info() {
		return "order info";
	}

	@HystrixCommand(fallbackMethod = "fallList", commandProperties = {
			@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000") })
	@GetMapping("/list")
	public String list() {
		// 调用user服务接口
		String res = restTemplate.getForEntity("http://spcloud-user/info", String.class).getBody();
		return res;
	}

	public String fallList() {
		return "fallList";
	}

}
